package com.ly.im.service.impl;

import com.ly.im.pojo.User;
import com.ly.im.service.LoginService;
import com.ly.im.service.UserService;
import com.ly.im.utils.JwtUtil;
import com.ly.im.utils.ResponseUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @Author LY
 * @create 2024/2/2 11:24
 * @Description login service impl
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Resource
    private UserService userService;
    @Resource
    private JwtUtil jwtUtil;

    @Override
    public Object login(String username, String password) {
        User user = userService.getUserByUserName(username);
        if (user == null){
            return ResponseUtils.username();
        }
        if (!user.getPassword().equals(password)){
            return ResponseUtils.username();
        }
        return ResponseUtils.ok(jwtUtil.createJWT(user));
    }
}
